package mrpheu.demo.server.classes;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ThreadPoolExecutor.AbortPolicy;

public class ThreadPoolChat {

//    private final int MIN = 10;
//    private final int MAX = 100;
    private ThreadPoolExecutor threadPool = null;
    private static RejectedExecutionHandler handler = new AbortPolicy();
    
    public ThreadPoolChat(int minClientPoolSize, int maxClientPoolSize,
            int clientKeepAliveTime, TimeUnit keepAliveTimeUnit,
            BlockingQueue<Runnable> waitQueue, ThreadFactory threadFactory,
            RejectedExecutionHandler handler) {
        this.threadPool = new ThreadPoolExecutor(minClientPoolSize,
                maxClientPoolSize, clientKeepAliveTime, keepAliveTimeUnit,
                waitQueue, threadFactory, handler);
    }
    
    public ThreadPoolChat(int minClientPoolSize, int maxClientPoolSize,
            int clientKeepAliveTime, TimeUnit keepAliveTimeUnit, BlockingQueue<Runnable> waitQueue) {
        this(minClientPoolSize, maxClientPoolSize, clientKeepAliveTime, keepAliveTimeUnit,
                waitQueue, Executors.defaultThreadFactory(), handler);
    }
    
//    public ThreadPoolExecutor getExecutor() {
//        return this.executor;
//    }
    
    public void execute(Runnable chatServerThread) {
        this.threadPool.execute(chatServerThread);
    }
    
    public boolean remove(Runnable chatServerThread) {
        return this.threadPool.remove(chatServerThread);
    }
    
}
